package org.hum.scaffold.dubbo;

import java.io.IOException;

import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;

@ComponentScan({"org.hum.scaffold.dubbo"})
@ImportResource({"classpath:dubbo/dubbo-export-demo.xml"})
public class DubboExportTests {


	// telnet localhost 20880
	@Test
	public void simpleExport() throws IOException {
		ServiceConfig<DemoService> serviceBean = new ServiceConfig<DemoService>();
		serviceBean.setApplication(new ApplicationConfig("huming"));
		serviceBean.setInterface(DemoService.class);
		serviceBean.setRef(new DemoServiceImpl());
		serviceBean.setVersion("1.2");
		serviceBean.setGroup("group3");
		serviceBean.setProtocol(new ProtocolConfig("dubbo", 20880));
		serviceBean.setRegistry(new RegistryConfig("N/A"));
		serviceBean.export();
		System.out.println("server start!");
		System.in.read();
	}
	
	@Test
	public void springExport() throws IOException {
		SpringApplication.run(DubboExportTests.class);
		System.out.println("Server start");
		System.in.read();
	}
}
